import java.util.*;

public class Set {  
	private ArrayList<Integer> a;

	public Set() {
		a = new ArrayList<Integer>();
	}

	public int[] toArray() {
		int[] ia = new int[a.size()];
		for (int i = 0; i < ia.length; i++) {
			ia[i] = a.get(i);
		}
		return ia;
	}
	
	// We should make a new Set.java, or just copy the old one and keep this
	// one as the edited. 
	

	//Break statements change to return instead to solve problems. 
	//Inserts an integer at the correct position, doesn't allow duplicates.
	//Sorted
	public void insert(int x) {
		for (int i = 0; i < a.size(); i++) {
			if (a.get(i) > x) {
				a.add(i, x);
				return; // break;
			} else {
				if (a.get(i) == x) {
					return; // break;
				}
			}
		}
		a.add(x);
	}

	public boolean member(int x) {
		for (int i = 0; i < a.size(); i++) {
			if (a.get(i) > x) {
				return false;
			} else {
				if (a.get(i) == x) {
					return true;
				}
			}
		}
		return false;
	}

	// Removes one to few 
	// doesn't take into consideration that the size of a gets smaller when
	// you remove a value. It should not increase i after it has removed it????
	public void section(Set s) {
		for (int i = 0, j = 0; i < a.size() && j < s.a.size();) {
			if (a.get(i).equals(s.a.get(j))) {
				a.remove(i);
				//i++; This was the bug
				j++;
			} else {
				if (a.get(i) < s.a.get(j)) {
					i++;
				} else {
					j++;
				}
			}
		}
	}
	
	// accepts if there is less than three values in the set. 
	// accepts if i and j are equal, this cannot be since they are supposed to
	// be different values. 
	public boolean containsArithTriple() {
		for (int i = 0; i < a.size(); i++) {
			for (int j = 0; j <= i; j++) {
				if(i!=j) // added to fix bug with same index i and j
				if (member(2 * a.get(i) - a.get(j)))
					return true;
			}
		}
		return false;
	}
}